#include "control_panel.h"
#include "ui_control_panel.h"

control_panel::control_panel(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::control_panel)
    , widget_(new QWidget())
    , lbl_(new QLabel("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", this))
    , table_(new table_view(QSize(lbl_->sizeHint().width(), 500)))
    , table2_(new table_view2(8, 3))
{
    ui->setupUi(this);

    ui->row_num_le->setText(QString::number(10));
    ui->col_num_le->setText(QString::number(2));

    ui->create_table_btn->click();




//    table_->show();
//    table2_->show();

    auto layout = new QVBoxLayout();
    layout->setContentsMargins(0, 0, 0, 0) ;
//    layout->setSizeConstraint(QLayout::SetMinAndMaxSize) ;

//    layout->addWidget(table_.get());
    layout->addWidget(table2_.get());

    layout->addWidget(lbl_);

    widget_->setLayout(layout);
    widget_->show();
}

control_panel::~control_panel()
{
    delete ui;
}

void control_panel::on_create_table_btn_clicked()
{
    table_->create_table(ui->row_num_le->text().toInt(), ui->col_num_le->text().toInt());
    table2_->create_table(ui->row_num_le->text().toInt(), ui->col_num_le->text().toInt());
}

void control_panel::on_add_row_btn_clicked()
{
    table_->add_row();
    table2_->add_row();
}

void control_panel::on_del_row_btn_clicked()
{
    table_->del_row();
    table2_->del_row();
}

void control_panel::on_add_col_btn_clicked()
{
    table_->add_col();
    table2_->add_col();
}

void control_panel::on_del_col_btn_clicked()
{
    table_->del_col();
    table2_->del_col();
}

void control_panel::on_autoresizel_btn_clicked()
{
    table_->auto_resize();
    table2_->auto_resize();

    widget_->resize(10, 10);
//    widget_->layout()->update();
//    widget_->updateGeometry();
}

void control_panel::on_print_sizes_btn_clicked()
{
}


void control_panel::on_clear_btn_clicked()
{
    table_->clear_table();
    table2_->clear_table();
}
